const express = require('express')
const updateDetail = express.Router()
const db = require('../../mysql/db')

function query(data) {
    data.shopName = String(data.shopName)
    data.commodityName = String(data.commodityName)
    return new Promise((resolve, reject) => {
        db.query(`
        UPDATE details SET 
    category = ?,id = ?, shopName = ?, shopPicture = ?, icon = ?, babyDescription = ?, sellerService = ?, 
    logisticsService = ?,shopIMG = ?, commodityName = ?, sales = ?, price = ?, nowPrice = ?, 
    detail = ?, detailIMG = ?, comments = ?, description = ? WHERE id = ?
    `, [
            data.category,
            data.id,
            data.shopName,
            data.shopPicture,
            data.icon,
            data.babyDescription,
            data.sellerService,
            data.logisticsService,
            data.shopIMG,
            data.commodityName,
            data.sales,
            data.price,
            data.nowPrice,
            data.detail,
            data.detailIMG,
            data.comments,
            data.description,
            data.id
        ], (err, results) => {
            if (err) {
                reject(err);
                console.log("商品更新失败！");
            } else {
                console.log("商品更新成功！");
            }
        });
    });
}
updateDetail.post('/updateDetail', (req, res) => {
    const result = query(req.body.values);
    res.send({
        code: 200, // 0 表示处理成功，1 表示处理失败
        message: 'post 请求成功！', // 状态的描述
        result: result, // 需要响应给客户端的数据
    });
});
module.exports = updateDetail
